package com.example.skinhelper;

import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ColorViewSetting implements ViewSetting {

    List<String> list = Arrays.asList(new String[]{
            "background",
            "textColor",
            "src"
    });


    @Override
    public List<String> getAttrNameList() {
        return list;
    }

    @Override
    public void setSkin(View view, String name, String valueId, Resources resources) {
        Log.d("ColorViewSetting", "setSkin: name=" + name + " valueId=" + valueId);
        int color = 0;
        if (valueId.charAt(0) != '@') {
            return;
        }
        try {
            Integer integer = Integer.valueOf(valueId.substring(1));
            if (IdUtils.findResById(integer).getType().equals("color")) {
                color = resources.getColor(integer);
            }
        } catch (Exception e) {
            return;
        }
        Log.d("ColorViewSetting", "setSkin: "+color);
        switch (name) {
            case "background":
                view.setBackgroundColor(color);
                break;

            case "textColor":
                if (view instanceof TextView) {
                    ((TextView) view).setTextColor(color);
                }
                break;
            case "src":
                if (view instanceof ImageView) {
                    ((ImageView) view).setImageDrawable(new ColorDrawable(color));
                }
                break;
        }
    }


}
